//
//  UserManager.m
//  test
//
//  Created by 朱圳 on 2018/1/13.
//  Copyright © 2018年 朱圳. All rights reserved.
//
#define User @"User"
#define GUser @"GUser"
#define SUser @"SUser"
#define Bdata  @"Bdata"
#import "JWUserManager.h"

@implementation JWUserManager
//偏好设置（preference）
//保存
+(void)save:(JWUserModel *)user{
    
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
#pragma -mark ——————————教务老师 -—————————————————————————————————
    [userDefaults setObject:user.phone forKey:@"phone"];
    [userDefaults setObject:user.jwID forKey:@"jwID"];
    [userDefaults setObject:user.jwPassword forKey:@"jwPassword"];
    [userDefaults setObject:user.time forKey:@"time"];
    [userDefaults setObject:user.qnumber forKey:@"qnumber"];
    [userDefaults setObject:user.pic forKey:@"jwpic"];
    [userDefaults setObject:user.birthday forKey:@"birthday"];
    [userDefaults setObject:user.messagetype forKey:@"messagetype"];
    [userDefaults setObject:user.sex forKey:@"sex"];
    [userDefaults setObject:user.name forKey:@"name"];
    [userDefaults setObject:user.wnumber forKey:@"wnumber"];
    [userDefaults removeObjectForKey:@"classification"];//先移除
    [userDefaults setObject:user.classification forKey:@"classification"];//再添加jiaojielist
    //交接流程
    [userDefaults setObject:user.jiaojielist forKey:@"jiaojielist"];
    /****************注册研究生***************************/
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user];
    [userDefaults setObject:data forKey:User];
    //立即同步
    [userDefaults synchronize];
}
+(JWUserModel *)me{
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    NSData *data = [userDefaults objectForKey:User];
    JWUserModel *user = nil;
    if (data) {
        user = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    }
    return user;
}
#pragma -mark ———————————研究生管理————————————————————
//保存
+(void)saveGR:(JWGRUsermodel *)GRuser{
    NSUserDefaults *GRUsermodels =[NSUserDefaults standardUserDefaults];
    [GRUsermodels setObject:GRuser.ID forKey:@"ID"];
    [GRUsermodels setObject:GRuser.phone forKey:@"phone"];
    [GRUsermodels setObject:GRuser.tname forKey:@"tname"];
    [GRUsermodels setObject:GRuser.password forKey:@"password"];
    [GRUsermodels setObject:GRuser.time forKey:@"time"];
    [GRUsermodels setObject:GRuser.qnumber forKey:@"qnumber"];
    [GRUsermodels setObject:GRuser.pic forKey:@"pic"];
    [GRUsermodels setObject:GRuser.birthday forKey:@"birthday"];
    [GRUsermodels setObject:GRuser.college forKey:@"college"];
    [GRUsermodels setObject:GRuser.jieshu forKey:@"jieshu"];
    [GRUsermodels setObject:GRuser.achievement forKey:@"achievement"];
    [GRUsermodels setObject:GRuser.sex forKey:@"sex"];
    [GRUsermodels setObject:GRuser.moneyway  forKey:@"moneyway"];
    [GRUsermodels setObject:GRuser.moneynumber forKey:@"moneynumber"];
    [GRUsermodels setObject:GRuser.name forKey:@"name"];
    [GRUsermodels setObject:GRuser.wnumber forKey:@"wnumber"];
    [GRUsermodels setObject:GRuser.address forKey:@"address"];
    [GRUsermodels setObject:GRuser.beizhu forKey:@"beizhu"];
    [GRUsermodels setObject:GRuser.message forKey:@"message"];
    [GRUsermodels setObject:GRuser.studentlist forKey:@"studentlist"];
    [GRUsermodels setObject:GRuser.othermoneys forKey:@"othermoneys"];
    
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:GRuser];
    [GRUsermodels setObject:data forKey:GUser];
    //立即同步
    [GRUsermodels synchronize];
}
+(void)updateGR:(JWGRUsermodel *)GRuser{
    NSUserDefaults *GRUsermodels =[NSUserDefaults standardUserDefaults];
    [GRUsermodels setObject:GRuser.gid forKey:@"gid"];
    [GRUsermodels setObject:GRuser.name forKey:@"name"];
    [GRUsermodels setObject:GRuser.phone forKey:@"phone"];
    [GRUsermodels setObject:GRuser.college forKey:@"college"];
    [GRUsermodels setObject:GRuser.address forKey:@"address"];
    [GRUsermodels setObject:GRuser.moneyway  forKey:@"moneyway"];
    [GRUsermodels setObject:GRuser.moneynumber forKey:@"moneynumber"];
    [GRUsermodels setObject:GRuser.achievement forKey:@"achievement"];
    [GRUsermodels setObject:GRuser.beizhu forKey:@"beizhu"];
    
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:GRuser];
    [GRUsermodels setObject:data forKey:GUser];
    //立即同步
    [GRUsermodels synchronize];

}
//使用
+(JWGRUsermodel *)Gme{
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    NSData *data = [userDefaults objectForKey:GUser];
    JWGRUsermodel *Guser = nil;
    if (data) {
        Guser = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    }
    return Guser;
}
#pragma -mark ——————————————————学生信息管理————————————————————
+(void)saveSD:(SDUserModel *)SDuser{
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    /****************学生***************************/
    [userDefaults setObject:SDuser.gid forKey:@"gid"];
    [userDefaults setObject:SDuser.sid forKey:@"sid"];
    [userDefaults setObject:SDuser.name forKey:@"name"];
    [userDefaults setObject:SDuser.sex forKey:@"sex"];
    [userDefaults setObject:SDuser.phone forKey:@"phone"];
    [userDefaults setObject:SDuser.college forKey:@"college"];
    [userDefaults setObject:SDuser.jieshu forKey:@"jieshu"];
    [userDefaults setObject:SDuser.goal forKey:@"goal"];
    [userDefaults setObject:SDuser.Applytime forKey:@"Applytime"];
    [userDefaults setObject:SDuser.QQ forKey:@"QQ"];
    [userDefaults setObject:SDuser.Winxin forKey:@"Winxin"];
    [userDefaults setObject:SDuser.BirthDay forKey:@"BirthDay"];
    [userDefaults setObject:SDuser.dadphone forKey:@"dadphone"];
    [userDefaults setObject:SDuser.mumphone forKey:@"mumphone"];
    [userDefaults setObject:SDuser.BuyCourse forKey:@"BuyCourse"];
    [userDefaults setObject:SDuser.classmoney forKey:@"classmoney"];
    [userDefaults setObject:SDuser.Baiduyun forKey:@"Baiduyun"];
    [userDefaults setObject:SDuser.Vyan forKey:@"Vyan"];
    [userDefaults setObject:SDuser.password forKey:@"password"];
    
    [userDefaults setObject:SDuser.classification forKey:@"classification"];
    
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:SDuser];
    [userDefaults setObject:data forKey:SUser];
    //立即同步
    [userDefaults synchronize];
}
//调用
+(SDUserModel *)SDme{
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    NSData *data = [userDefaults objectForKey:SUser];
    SDUserModel *Suser = nil;
    if (data) {
        Suser = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    }
    return Suser;
}


//退出登录
+(void)loginOut{
    
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    [userDefaults removeObjectForKey:User];
    [userDefaults removeObjectForKey:@"name"];
    [userDefaults removeObjectForKey:@"classification"];
}

+(BOOL)isJWLogining{
    
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    NSString *userName = [userDefaults objectForKey:@"name"];
    NSString *classification = [userDefaults objectForKey:@"classification"];
    
    if (userName && classification) {
        return YES;
    }else{
        return NO;
    }
}
@end
